import Vue from 'vue';
const eventBus = new Vue();

export default {
  install() {
    this.showHide();
    // type为onShow，onHide
    Vue.prototype.$addEventListener = (type, fn) => {
      eventBus.$on(type, fn);
    };
  },
  showHide() {
    let showHideLock = true;
    window.registerWebListener('onShow', () => {
      if (!showHideLock) {
        showHideLock = true;
        eventBus.$emit('onShow');
      }
    });
    window.registerWebListener('onHide', () => {
      if (showHideLock) {
        showHideLock = false;
        eventBus.$emit('onHide');
      }
    });
  },
};
